package com.wzh.activity.conf;

import com.wzh.activity.dao.ActivityDao;
import com.wzh.activity.entity.ActivityEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author WZH
 * @title: MYRunner
 * @projectName miaosha
 * @description:
 * @date 2022/2/28
 */
@Component
public class MyRunner implements ApplicationRunner {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private ActivityDao activityDao;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<ActivityEntity> activitys = activityDao.selectList(null);
        activitys.stream().forEach(item->{
            redisTemplate.boundHashOps("activity").put("item"+item.getId(),item);
        });
    }
}
